package iagovsothello.gui;

import iagovsothello.ai.*;
import iagovsothello.core.*;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.util.Arrays;
import java.util.HashMap;


public class HashTest {

	private static int dimension = 8;
	private static int[][] grid = new int[dimension][dimension];
	
	private static HashMap<String,Integer> hashTable;
	
	//cento milioni di test
	private static int testCount = 1000000;
	
	//ogni quanti test stampare a video delle informazioni
	private static int step = 100000;
	
	private static int currentCount;
	
	public static void main(String[] args) 
	{	
		hashTable = new HashMap<String,Integer>();
		for (int i = 0; i < dimension; i++)
		{
			for (int j = 0; j < dimension; j++)
			{
				grid[i][j] = 0;
			}
		}
		
		currentCount = 0;
		next(0,0);
	}
	
	public static void next(int i, int j)
	{
		if (i < dimension)
		{
			if (j < dimension)
				next(i,j+1);
			else
				next(i+1,0);
		}
		
		if (i == dimension-1 && j == dimension-1 && currentCount < testCount)
		{
			for (int k = 0; k < 2; k++)
			{
				grid[i][j] = k;
				if (currentCount%step == 0)
				{
					System.out.println("------------------------------------------------");
					System.out.print("COMBINAZIONE CORRENTE: ");
					printGrid();
					System.out.println("DIMENSIONE TABELLA HASH: "+hashTable.size());
				}
//				System.out.print("("+i+","+j+"): ");
//				printGrid();
				
				String s = string();
				if (hashTable.containsKey(s))
				{
					System.out.println(s+" ("+(hashTable.get(s)+1)+")");
					hashTable.put(s, hashTable.get(s)+1);
				}
				else
				{
					hashTable.put(s, 1);
//					System.out.println("SIZE: "+hashTable.size());
				}
//				System.out.println(v);
				
				currentCount++;
			}
			
			
			
		}
		else if (i < dimension && j < dimension && currentCount < testCount)
		{
//			System.out.print("("+i+","+j+"): ");
			grid[i][j] = 1;
			next(i,j+1);
			grid[i][j] = 2;
			next(i,j+1);
			grid[i][j] = 0;
		}
	}
	
	public static void printGrid()
	{
		for (int i = 0; i < dimension; i++)
		{
			for (int j = 0; j < dimension; j++)
			{
				System.out.print(grid[i][j]);
			}
		}
		System.out.println();
	}
	
	public static long hashTest3()
	{
		String nm = "";
		for (int i = 0; i < dimension; i++)
		{
			for (int j = 0; j < dimension; j++)
			{
				nm = nm + grid[i][j];
			}
		}
		return nm.hashCode();
	}
	
	public static String string()
	{
		String s = "";
		for (int i = 0; i < dimension; i++)
		{
			for (int j = 0; j < dimension; j++)
			{
				s = s + grid[i][j];
			}
		}
		return s;
	}
	
	public static void createSwitch(int lines)
	{
		try {
			BufferedReader r = new BufferedReader(new FileReader("primes.txt"));
			long prime;
			for (int i = 0; i < lines; i++)
			{
				try {
					prime = Long.parseLong(r.readLine());
					System.out.println("case "+i+": return "+prime+"L;");
				} catch (NumberFormatException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			try {
				r.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}
